/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-11-26
*/
package com.rzico.account.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.account.entity.FoundationFlow;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Enterprise;
import com.rzico.basics.service.EnterpriseService;
import com.rzico.entity.Filter;
import com.rzico.entity.Pageable;
import com.rzico.entity.PageResult;
import com.rzico.account.entity.Foundation;
import com.rzico.account.service.FoundationService;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.Api;
import com.rzico.util.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;

/**
 * 基金管理控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-11-26
 */
@Api(description = "基金管理接口")
@RestController
@RequestMapping("/admin/foundation")
public class FoundationAdminController extends BaseController {

    @Autowired
    private FoundationService foundationService;

    @Autowired
    private EnterpriseService enterpriseService;


    /**
     * 查询基金管理
     *
     * @return
    */
    @ApiOperation("查询基金管理")
    @GetMapping("/getInfo")
    @ApiImplicitParams({@ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "String", paramType = "query") ,
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "String", paramType = "query")
    })
    public CommResult<Foundation> list(Date startDate, Date endDate, Pageable pageable) {
        Enterprise enterprise = enterpriseService.getCurrent();
        Foundation foundation = foundationService.getInfo(enterprise.getId());
        return CommResult.success(foundation);
    }


    /**
     * 更新基金
     *
     * @param foundation
     * @return
     */
    @Log(desc = "更新基金", type = Log.LOG_TYPE.UPDATE)
    @ApiOperation("更新基金")
    @PostMapping("/update")
    public CommResult<Foundation> update(@RequestBody Foundation foundation) {
        foundation.setAtvy(null);
        foundation.setBonus(null);
        foundation.setFund(null);
        foundation.setVip1(null);
        foundation.setVip2(null);
        foundation.setVip3(null);
        foundation.setVip4(null);
        foundation.setVip5(null);
        int affectCount = foundationService.updateByPrimaryKeySelective(foundation);
        if (affectCount <= 0){
            return CommResult.error();
        }
        Foundation result = foundationService.findById(foundation.getId());
        return CommResult.success(result);
    }

}
